<div id="formDiv"></div>
<script type="text/html" id="warehouseProductionOrderformContent">
    <form lay-filter="warehouseProductionOrderForm" id="warehouseProductionOrderForm" class="layui-form open-form">
        <div class="open-model">
            <div class="open-auto">
                <div>
                    <table class="layui-table" id="111" lay-filter="111">
                        <thead>
                        <tr>
                            <th lay-data="{field:'materialNumber', width:150, sort: true, fixed: 'left'}">
                                选择上机记录编号
                            </th>
                            <th lay-data="{field:'materialName', width:150, sort: true, fixed: 'left'}">所属产品订单
                            </th>

<!--                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">产品规格码</th>-->
                            <th lay-data="{field:'materialSpec', width:150, sort: true, fixed: 'left'}">计划产量</th>
<!--                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">物料料号</th>-->
                                                <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">选择产线</th>
                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">品种</th>
                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">牌号</th>
                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">厂家</th>
                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">原始捆包号</th>
                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">上机时间</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>

                            <td class="chooseCode">
                                {{# if(d.eventName !== 'edit' && d.eventName !== 'detail'){ }}
<!--                                <select id="computerPracticeCodeI" name="computerPracticeCodeI"-->
<!--                                        lay-filter="computerPracticeCodeI"  lay-search required></select>-->
                                <input class="layui-input adv-disable" id="computerPracticeCodeI"  lay-filter="computerPracticeCodeI"  name="computerPracticeCodeI" type="hidden"/>
                                <input class="layui-input adv-disable" id="computerPracticeCode"  lay-filter="computerPracticeCode" placeholder="请选择上机记录编号" readonly name="computerPracticeCode" lay-search required />

                                {{# } }}
                                {{# if(d.eventName === 'edit' || d.eventName === 'detail'){ }}
                                <div  style="width: 100%;height: 100%;display: flex;align-items: center;justify-content: center;text-align: center"  id="computerPracticeIdName" ></div>
                                <div class="mask"></div>
                                {{# } }}
                            </td>
                            <td>
                                <input class="layui-input adv-disable" id="productionOrderNumber" disabled
                                       name="productionOrderNumber"/>
                            </td>
                         
<!--                            <td>-->
<!--                                <input type="text" class="layui-input" disabled id="productSpecCode"-->
<!--                                       name="productSpecCode"/>-->
<!--                            </td>-->
                            <td>
                                <input class="layui-input adv-disable" id="plannedQuantity" disabled name="plannedQuantity" />
                            </td>
                  
                           

<!--                            <td>-->
<!--                                <input type="text" class="layui-input" disabled name="materialNumber"/>-->
<!--                            </td>-->
                             <td>
                                <input type="text" class="layui-input" disabled name="productionLineName"/>
                            </td>
                              <td>
                                <input type="text" class="layui-input" disabled name="productVarietyName"/>
                            </td>
                              <td>
                                <input type="text" class="layui-input" disabled name="productMarkName"/>
                            </td>
                              <td>
                                <input type="text" class="layui-input" disabled name="productProducerName"/>
                            </td>
                            <td>
                                <input type="text" class="layui-input" disabled name="userBundleCode"/>
                            </td>
                            <td>
                                <input class="layui-input adv-disable" id="createTime" disabled name="createTime"/>
                            </td>
                        </tr>
                        </tbody>
                    </table>


                    <div class="layui-form-item tableContent">
<!--   {{# if(d.eventName !== 'detail'){ }} -->
                        <button class="layui-btn" type="button" id="Configure">添加记录</button>
<!--                         {{# } }} -->
                        <table class="layui-table" id="processPlanFormTable" lay-filter="processPlanFormTable"></table>
                    </div>


                    <script type="text/html" id="processPlanFormTableBar">
                        {{# if(d.eventName !== 'detail'){ }}
                        <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" type="button">删除</button>
                        {{# } }}
                    </script>


<div class="layui-form-item text-right">
    <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
    <button class="layui-btn" lay-filter="formSubmit" type="button" lay-submit id="formSubmitUp">提交</button>
</div>
</div>
</div>
</div>
</form>
</script>

<script type="text/html" id="warehouseMaterialRequisitionRecordFormTableBar">
    <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" type="button">删除</button>
</script>
<script type="text/html" id="customerSku">
    <div class="open-form">
        <div class="open-model">
            <div class="open-auto">
                <button class="layui-btn " id="addCustomerSku">确认选择</button>
                <table class="layui-table" id="customerSkuTable"></table>
            </div>
        </div>
    </div>
</script>
<script type="text/html" id="warehouseMaterialRequisitionRecordForm">
    <div class="open-form">
        <div class="open-model">
            <div class="open-auto">
                <table class="layui-table" id="warehouseMaterialRequisitionRecordTable"
                       lay-filter="warehouseMaterialRequisitionRecordTable"></table>
            </div>
        </div>
    </div>
</script>
<script>
    // 假设使用一个简单的计数器来生成 userBundleCode
    let bundleCodeCounter = 1;
    let itemData = {}
    let oneItem = {}
    let kData
    let practiceId = 0

    layui.use(["layer", "form", "table", "admin", "laydate", "upload", "laytpl"], async function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        let laydate = layui.laydate;
        let laytpl = layui.laytpl;
        const nowData = { ...parentData };
        let data = nowData?.data;
        let computerPracticeCodeI = nowData?.computerPracticeCodeI;
        let skuList = [];

        const workshopData = [{ typeName: "成品", productType: 1 }, { typeName: "余料", productType: 2 }, { typeName: "废料", productType: 3 }];
        const workshopList = workshopData.map((v) => {
            return {
                label: v.typeName,
                value: v.productType
            };
        });
        const productionLineData = await admin.reqPro("warehouse/warehouse/productionLine/list", {});
        const productionLineList = productionLineData.data.map((v) => {
            return {
                label: v.workshopName,
                value: v.id,
                productType: v.productType
            };
        });
        if (nowData.eventName == "detail") {
            admin.setFormDisable("#warehouseProductionOrderForm", true);
            console.log("detail")
            $("#formSubmitUp").hide(); // 隐藏提交按钮
            $("#computerPracticeCode").prop("disabled", true); // 禁用选择上机记录按钮
            form.render();
        }

        laytpl(warehouseProductionOrderformContent.innerHTML).render(nowData, function (html) {
            $("#formDiv").after(html);
        });
        // 设置 computerPracticeCode 的值
        if (nowData.eventName === "edit" || nowData.eventName === "detail") {
            // form.val("warehouseProductionOrderForm", {
            //     computerPracticeIdName: nowData.data.computerPracticeCode
            // });
            // form.render();
            $("#computerPracticeIdName").html(nowData.data.computerPracticeCode);
            // console.log('12356',nowData.data.computerPracticeCode)
        }

        await admin.initDataSelectPro(
            "warehouse/warehouse/computerPractice/list?page=1&limit=999&status=1",
            // "warehouse/warehouse/materialRequisitionRecord/list",
            { limit: 99999 },
            "computerPracticeCodeI",
            "上机编号",
            async (d, obj) => {
                var item = {
                    id: "",
                    createTime: "",
                    materialNumber: "",
                    computerPracticeId: "",
                    processingReportDetailId: "",
                    productionPlanCode: "",
                    productionOrderNumber: "",
                    requisitionQuantity: '',
                    plannedQuantity: "",
                    plannedDeliveryTime: "",
                    plannedProductionTime: "",
                    customerProductCode: "",
                    productSpecCode: "",
                    workshopName: "",
                    productId: "",
                    productionLineName: "",
                    productionPlanRemark: "",
                    productionuserBundleCodePlanCode: "",
                    userBundleCode: "",
                    productProducerName: "",
                    productMarkNameName:"",
                    productVarietyName:"",
                    productBrand: "",
                    productMainUnit: "",
                    grossWeight: "",
                    netWeight: ""
                }
                $("#processingReportDetailId").empty();
                form.val("warehouseProductionOrderForm", item);
                $("#materialDetail").text("无物料");
                $("#materialDetail").attr("title", "无物料");
                // 清空排产信息列表
                table.reload("processPlanFormTable", {
                    data: []
                });

                bundleCodeCounter = 1




                itemData = {}
                if (d.value) {
                    // 存储数据
                    practiceId = d.value
                    if (nowData.eventName == "edit") {
                        practiceId = nowData.data.computerPracticeId
                    }
                    kData = await admin.reqPro("warehouse/warehouse/computerPractice/selectComputerPractice", { id: d.value });
                    oneItem = kData.data
                    if (oneItem) {
                        oneItem.userBundleCode = oneItem.warehouseMaterialRequisitionRecordDetail.userBundleCode
                        form.val("warehouseProductionOrderForm", oneItem);

                    } else {
                        form.val("warehouseProductionOrderForm", item);
                    }
                    itemData = { ...kData.data.warehouseMaterialRequisitionRecordDetail };
                    console.log(itemData)
                } else {
                    itemData = {};
                }



            },
            // "productionPlanCode"
            "computerPracticeCode"
        );

        $("#computerPracticeCode").click(function () {
            if (nowData.eventName === "detail" || computerPracticeCodeI) {
                return;
            }
            admin.formOpen({
                area: "90%",
                offset: ['6%', '6%'],
                title: "选择上机编号",
                path: "components/warehouse/product/warehouseProcessingSelect.html",
                success: function () {
                    // parentData.notIds = table.cache["purchasePlanFormTable"].map((v) => v.id);
                    // parentData.customerId = $("#customerId").val();
                    // parentData.productStatus  = 3
                },
                end: async function () {
                    // 清空排产信息列表
                    var item = {
                        id: "",
                        createTime: "",
                        materialNumber: "",
                        computerPracticeId: "",
                        processingReportDetailId: "",
                        productionPlanCode: "",
                        productionOrderNumber: "",
                        requisitionQuantity: '',
                        plannedQuantity: "",
                        plannedDeliveryTime: "",
                        plannedProductionTime: "",
                        customerProductCode: "",
                        productSpecCode: "",
                        workshopName: "",
                        productId: "",
                        productionLineName: "",
                        productionPlanRemark: "",
                        productionuserBundleCodePlanCode: "",
                        userBundleCode: "",
                        productProducerName: "",
                        productMarkNameName:"",
                        productVarietyName:"",
                        productBrand: "",
                        productMainUnit: "",
                        grossWeight: "",
                        netWeight: ""
                    }
                    if(childData.SelectList && childData.SelectList.length){
                        table.reload("processPlanFormTable", {
                            data: []
                        });
                        let data=childData.SelectList[0]
                        bundleCodeCounter = 1
                        itemData = {}
                        // 存储数据
                        practiceId = data.id
                        if (nowData.eventName == "edit") {
                            practiceId = nowData.data.computerPracticeId
                        }
                        kData = await admin.reqPro("warehouse/warehouse/computerPractice/selectComputerPractice", { id: data.id });
                        oneItem = kData.data
                        if (oneItem) {
                            oneItem.userBundleCode = oneItem.warehouseMaterialRequisitionRecordDetail.userBundleCode
                            oneItem.computerPracticeCode=data.computerPracticeCode
                            oneItem.computerPracticeCodeI=data.id
                            form.val("warehouseProductionOrderForm", oneItem);

                        } else {
                            form.val("warehouseProductionOrderForm", item);
                        }
                        kData.data.warehouseMaterialRequisitionRecordDetail.productSpecCode=kData.data.productSpecCode;
                        kData.data.warehouseMaterialRequisitionRecordDetail.bundleQuantity=kData.data.bundleQuantity
                        itemData = { ...kData.data.warehouseMaterialRequisitionRecordDetail };
                        console.log(itemData)

                    }
                }
            });
        })


        table.on("tool(warehouseMaterialRequisitionRecordFormTable)", function (obj) {
            var d = obj.data; // 获取当前行的数据
            var layEvent = obj.event; // 获取事件名（edit 或 del）
            if (obj.tr) {
                obj.tr.on("click", function (e) {
                    e.preventDefault(); // 防止默认行为
                });
            }
            if (layEvent == "del") {
                const index = $(obj.tr[0]).data("index");
                let list = table.cache["warehouseMaterialRequisitionRecordFormTable"].filter((v) => {
                    return v["LAY_TABLE_INDEX"] != index;
                });
                table.reload("warehouseMaterialRequisitionRecordFormTable", {
                    data: list
                });
            }
        });

        const tableVal = table.render({
            elem: "#processPlanFormTable",
            page: false,
            limit: 999999,
            height: 400,
            data: [

            ],
            cols: [
                [
                    { type: "numbers", title: "序号" },
                    { title: "成品规捆包号", field: "finishedProductBundleCode", },
                    { field: "originalBundleCode", align: "center", title: "原始捆包号" },
                    { type: "productSpecCode", title: "规格", templet: admin.setTableInput("productSpecCode", nowData.eventName == "detail", "productSpecCode") },
                    {
                        field: "productType",
                        title: "捆包类型",
                        templet: function (d) {
                            return admin.setTableSelect("productType", workshopList, nowData.eventName == "detail", "productType")(d);
                        }
                    },
                    // { type: "productSpecCode", title: "成品规格", field: "productSpecCode"},
                    { type: "theoreticalQuantity", title: "理论张数", templet: admin.setTableInput("theoreticalQuantity", nowData.eventName == "detail", "theoreticalQuantity") },
                    { field: "theoreticalWeight", title: "理论重量",
                        templet: function (d) {
                            // 否则计算捆包数量：计划数 / 捆包件数（取整）
                            const theoreticalWeight = Number(d.netWeight2)*Number(d.bundleQuantity)*Number(d.theoreticalQuantity);
                            return theoreticalWeight || '0';
                        }},
                    { type: "actualWeight", title: "实际磅重", field: "actualWeight", templet: admin.setTableInput("actualWeight", nowData.eventName == "detail", "actualWeight") },
                    { type: "actualQuantity", title: "实际张数", templet: admin.setTableInput("actualQuantity", nowData.eventName == "detail", "actualQuantity") },
                    { field: "remark", title: "备注信息", templet: admin.setTableInput("remark", nowData.eventName == "detail", "remark") },
                    { title: "操作", toolbar: "#processPlanFormTableBar" }
                ]
            ],

            done: function (tableData) {
                let debounceTimer; // Moved to outer scope
                admin.tableInputChangeByClass("processPlanFormTable", "theoreticalWeight");
                admin.tableInputChangeByClass("processPlanFormTable", "productSpecCode");
                admin.tableInputChangeByClass("processPlanFormTable", "actualWeight");
                admin.tableInputChangeByClass("processPlanFormTable", "actualQuantity");
                admin.tableInputChangeByClass("processPlanFormTable", "remark");
                tableData.data.forEach((v, index) => {
                    laydate.render({
                        elem: ".plannedProductionTime" + v.LAY_TABLE_INDEX,
                        type: "datetime",
                        done: function (value, date, endDate) {
                            v.plannedProductionTime = value;
                        }
                    });
                });



                admin.tableInputChangeByClass("processPlanFormTable", 'theoreticalQuantity', function (index, value, tableData, field, tableId) {
                    let rowIndex = tableData.findIndex((v) => v["LAY_TABLE_INDEX"] == index);
                    if (rowIndex > -1) {
                        tableData[rowIndex].theoreticalQuantity = parseInt(value) || 0;
                        clearTimeout(debounceTimer);
                        debounceTimer = setTimeout(() => {
                            table.reload(tableId, {
                                data: tableData.data,
                                where: { LAY_TABLE_INDEX: index }
                            });
                        }, 500);
                    }
                });

            }
        });



        admin.tableSelectChange("processPlanFormTable", "productType", (index, value, tableData, field, tableId) => {
            // 不再在这里添加新行
            tableVal.reload({
                data: tableData
            });
        });

        if (data && data.id) {
            await admin.initDataSelectPro(
                "warehouse/warehouse/productionOrder/list",
                {
                    customerId: data.customerId
                },
                "productionOrderId",
                "生产订单编号",
                async (d, obj) => {
                    $("#productId").empty();
                    form.val("warehouseProductionOrderForm", { productionOrderNumber: "", productId: "" });
                    if (d.value) {
                        delete obj.id;
                        form.val("warehouseProductionOrderForm", { productionOrderNumber: obj.productionOrderNumber });

                        const { data } = await admin.reqPro("warehouse/warehouse/productionOrder/selectProductionDetail", { id: d.value });
                        admin.initDataSelect(data.warehouseProductionOrderDetailList, {}, "productId", null, "产品名称", "productCode", "productId");
                        form.on("select(productId)", function (d) {
                            let obj = data.warehouseProductionOrderDetailList.find((v) => v.productId == d.value);
                            delete obj.id;

                            form.val("warehouseProductionOrderForm", obj);
                        });
                    }
                },
                "productionOrderNumber"
            );
            const res = await admin.reqPro("warehouse/warehouse/productionOrder/selectProductionDetail", { id: data.productionOrderId });
            admin.initDataSelect(res.data.warehouseProductionOrderDetailList, {}, "productId", data.productId, "产品名称", "productCode", "productId");

            form.val("warehouseProductionOrderForm", data);
            $("#materialDetail").text(data.materialNumber ? data.materialNumber : "无物料");

            if (nowData.productId) {
                tableVal.reload({
                    data: data.warehouseProcessingReportDetailList.filter((v) => v.id == nowData.productId)
                });
            } else {
                tableVal.reload({
                    data: data.warehouseProcessingReportDetailList
                });
            }
        } else {
            // tableVal.reload({
            //     data: [
            //         {
            //             userBundleCode: "userBundleCode-0",
            //             productType: "",
            //             productionLineId: "",
            //             plannedProductionTime: "",
            //             plannedQuantity: "",
            //             remark: ""
            //         }
            //     ]
            // });
        }


        /*从上机操作进来*/
        if(computerPracticeCodeI && computerPracticeCodeI!==''){
            let res=await admin.reqPro("warehouse/warehouse/computerPractice/list?page=1&limit=999&status=1", {});

            let data=res.data.filter(i=>i.id==computerPracticeCodeI)
            if(data.length){
                bundleCodeCounter = 1
                itemData = {}
                // 存储数据
                practiceId = data[0].id
                kData = await admin.reqPro("warehouse/warehouse/computerPractice/selectComputerPractice", { id: data[0].id });
                oneItem = kData.data
                if (oneItem) {
                    oneItem.userBundleCode = oneItem.warehouseMaterialRequisitionRecordDetail.userBundleCode
                    oneItem.computerPracticeCode=data[0].computerPracticeCode
                    oneItem.computerPracticeCodeI=data[0].id
                    form.val("warehouseProductionOrderForm", oneItem);
                } else {
                    form.val("warehouseProductionOrderForm", item);
                }
                kData.data.warehouseMaterialRequisitionRecordDetail.productSpecCode=kData.data.productSpecCode;
                kData.data.warehouseMaterialRequisitionRecordDetail.bundleQuantity=kData.data.bundleQuantity
                itemData = { ...kData.data.warehouseMaterialRequisitionRecordDetail };
                console.log(itemData)
            }

        }

        //主框确定
        form.on("submit(formSubmit)", function (d) {

            delete oneItem.warehouseProcessingReportDetailList
            oneItem.computerPracticeTime = oneItem.createTime
            oneItem.computerPracticeId = practiceId
            let formData = oneItem;
            formData.warehouseMaterialRequisitionRecordDetailList = table.cache["processPlanFormTable"];
            let addData = formData
            if (table.cache["processPlanFormTable"].length == 0) {
                layer.msg("请添加数据");
                return false
            }
            formData.scheduleQuantity = Number(formData.scheduleQuantity);
            formData.remainingProductionSchedule = Number(formData.remainingProductionSchedule);
            formData.productionOrderDetailId = Number(formData.productionOrderDetailId);
            formData.warehouseProcessingReportDetailList = table.cache["processPlanFormTable"].map((v) => {
                v.plannedQuantity = Number(v.plannedQuantity);
                v.workshopName = workshopList.find((v1) => v1.value == v.productType)?.label;
                v.productionLineName = productionLineList.find((v1) => v1.value == v.productionLineId)?.label;
                return v;
            });
            if (formData.warehouseProcessingReportDetailList.some((v) => v.productType == "" && v.productionLineId == "")) {
                layer.msg("请完善表格数据");
                return false;
            }
            delete formData.createTime
            formData.plannedQuantity = formData.warehouseProcessingReportDetailList.reduce((v, c) => v + Number(c.plannedQuantity), 0);
            if (formData.plannedQuantity > formData.scheduleQuantity) {
                layer.confirm("计划生产数量大于需求数，是否继续", { icon: 3, title: "提示" }, function (index) {
                    submitForm(formData);
                });
            } else {
                submitForm(addData);
            }

            return false;
        });

        function submitForm(formData) {
            if (!table.cache["processPlanFormTable"]) {
                layer.msg("请添加数据数据");
                return false
            }
            if (nowData.eventName == "add") {
                delete formData.id;
                admin.req(
                    "warehouse/warehouse/processingReport/add",
                    JSON.stringify(formData),
                    function (res) {
                        layer.closeAll("loading");
                        if (res.code == 200) {
                            layer.msg(res.msg, { icon: 1 });
                            if(computerPracticeCodeI && computerPracticeCodeI!==''){
                                table.reload("warehouseComputerPracticeTable");
                            }else{
                                table.reload("ProductionOrderTable");
                            }
                            layer.closeAll("page");
                        } else {
                            layer.msg(res.msg, { icon: 2, time: 1000 });
                        }
                    },
                    "POST",
                    false,
                    "application/json"
                );
            } else if (nowData.eventName == "edit") {
                console.log(formData.warehouseProcessingReportDetailList)
                let editData = nowData.data
                editData.warehouseProcessingReportDetailList = formData.warehouseProcessingReportDetailList
                admin.req(
                    "warehouse/warehouse/processingReport/updateProcessingReport",
                    JSON.stringify(editData),
                    function (res) {
                        layer.closeAll("loading");
                        if (res.code == 200) {
                            layer.msg(res.msg, { icon: 1 });
                            table.reload("ProductionOrderTable");
                            layer.closeAll("page");
                        } else {
                            layer.msg(res.msg, { icon: 2, time: 1000 });
                        }
                    },
                    "POST",
                    false,
                    "application/json"
                );
            }
        }

        table.on("tool(processPlanFormTable)", function (obj) {
            var d = obj.data; // 获取当前行的数据
            var layEvent = obj.event; // 获取事件名（edit 或 del）
            if (obj.tr) {
                obj.tr.on("click", function (e) {
                    e.preventDefault(); // 防止默认行为
                });
            }
            if (layEvent == "del") {
                const index = $(obj.tr[0]).data("index");
                let list = table.cache["processPlanFormTable"].filter((v) => {
                    return v["LAY_TABLE_INDEX"] != index;
                });
                table.reload("processPlanFormTable", {
                    data: list
                });
            }
        });

        $("#Configure").click(function () {
            if ($("#computerPracticeCode").val() === "") {
                layer.msg("请选择上机记录编号");
                return;
            }


            if (table.cache["processPlanFormTable"].some((v) => v.productType == "" && v.productionLineId == "")) {
                layer.msg("请完善表格数据");
            } else {

                let itData = table.cache["processPlanFormTable"][0];
                console.log(itData,"itdata")
                let codeOne = '';
                if (nowData.eventName === "edit") {
                    // 生成 originalBundleCode
                    codeOne = itData.originalBundleCode
                    itData.userBundleCode = itData.originalBundleCode;
                    itData.productSpecCode = itData.productSpecCode ? itData.productSpecCode : '无';
                    itData.grossWeight = itData.theoreticalWeight;
                    // 更新 bundleCodeCounter 为列表中的最大 finishedProductBundleCode 值
                    let maxCode = 0;
                    table.cache["processPlanFormTable"].forEach(item => {
                        const match = item.finishedProductBundleCode.match(/-(\d+)$/);
                        if (match) {
                            const num = parseInt(match[1], 10);
                            if (num > maxCode) {
                                maxCode = num;
                            }
                        }
                    });
                    bundleCodeCounter = maxCode + 1; // 设置为最大值加一
                }


                if (nowData.eventName !== "edit") {
                    itData = itemData
                    codeOne = itemData.userBundleCode
                }
                console.log(itData,"iyyuu")

                const newOriginalBundleCode = codeOne + '-' + bundleCodeCounter++;
                let theoreticalWeight=Number(itData.bundleQuantity)*Number(itData.netWeight)*Number(itData.bundleQuantity)
                // 创建新的行数据
                const newRow = {
                    originalBundleCode: itData.userBundleCode,
                    finishedProductBundleCode: newOriginalBundleCode,
                    bundleQuantity:itData.bundleQuantity,
                    theoreticalQuantity: itData.bundleQuantity,
                    actualWeight: theoreticalWeight,
                    productType: "",
                    plannedQuantity: "",
                    remark: "",
                    theoreticalWeight: theoreticalWeight,
                    netWeight: oneItem.netWeight,
                    netWeight2:itData.netWeight,
                    productSpecCode: itData.productSpecCode ? itData.productSpecCode : '无'
                };

                // 将新行添加到表格数据中
                table.cache["processPlanFormTable"].push(newRow);

                // 重新加载表格以显示新的数据行
                tableVal.reload({
                    data: table.cache["processPlanFormTable"]
                });
            }
        });

        $("#warehouseProductionOrderForm .layui-table-body").css("overflow", "visible");
        $("#warehouseProductionOrderForm .layui-table-box").css("overflow", "visible");
        $("#warehouseProductionOrderForm .layui-table-view").css("overflow", "visible");
    });
</script>

<style>
    #warehouseProductionOrderForm .layui-form-label {
        width: 125px;
    }

    #warehouseProductionOrderForm .layui-input-block {
        margin-left: 155px;
    }

    #warehouseProductionOrderForm .layui-form-item .layui-inline {
        /* margin-bottom: 5px; */
        margin-right: 0px;
    }

    #warehouseProductionOrderForm .layui-table-cell {
        overflow: visible !important;
    }

    .chooseCode {
        position: relative;

        .mask {
            position: absolute;
            width: 100%;
            height: 100%;
            background: rgba(158, 157, 157, 0.1);
            top: 50%;
            left: 50%;
            z-index: 2;
            transform: translate(-50%, -50%);
        }
    }
</style>